﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OrmAuto;
using System.Data.Objects.DataClasses;
using System.Web.DynamicData;

public partial class Adm_GestioneDb : System.Web.UI.Page
{
   Querier mQuery =new Querier ();
   protected string mMex =string.Empty ;
   
  protected void Page_Init(object sender, EventArgs e)
		{
				bindGridTabelle();	
		}//Fm
   
    protected void Page_Load(object sender, EventArgs e)
    {
    												
    }

				protected void bindGridTabelle()
				{				   
						var visibleTables = MetaModel.Default.Tables ;
						if (visibleTables.Count == 0)
								throw new InvalidOperationException("Nessuna tabella trovata");
								  
						this.GridView1.DataKeyNames = new[] { "Name" };  
						GridView1.DataSource = visibleTables ;
						GridView1.DataBind();   
						
				}//fM

				protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
				{
						GridViewRow riga = GridView1.SelectedRow;
						var celle =	riga.Cells;
						
						string tabella =string.Empty ;
						foreach (var item in celle)
						{
								var c = item as DataControlFieldCell ; 
								if(c== null) continue ;
							 if(c.ContainingField.SortExpression.Equals("name", StringComparison.CurrentCultureIgnoreCase ) )
								{tabella  = c.Text; break ; }
						}
						if(!string.IsNullOrEmpty(tabella) )
								Server.Transfer( string.Format("GestDB_Stati.aspx?table={0}",tabella), false);
						
				}//fM

				protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
				{
						GridView1.PageIndex = e.NewPageIndex;
						bindGridTabelle(); 
				}//fM
				
				

				private void bindGrid()
				{
						using (var DAL = mQuery.getDAL())
						{
						
						}
				}//fM



				protected void GridView1_DataBound(object sender, EventArgs e)
				{

				}
}//fC
